import {observable as o, computed as c, action as a} from 'mobx';
import _ from 'lodash';
import axios from 'core/axios';
import RootStore from 'core/Store.js';
import request from 'core/request.js';
import Im from 'immutable';


class Store extends RootStore {
    constructor(args) {
        super(args);
    }

    @o loading = false;
    @o canLoadChildren = false;
    @o countryCodeList = [];
    @o defaultCode = {};

    will() {
    }

    showLoading() {
        this.loading = true;
    }

    hideLoading() {
        this.loading = false;
    }

    getCountryCodeList() {
        request({
            url: $$.api('getCountryCodeList'),
        }).then(res => {
            this.countryCodeList = res.data;
            this.defaultCode = this.countryCodeList[0];
        });
    }


    mount() {
        if (!$$.utils.getCookie('sessionId')) {
            global.window.location.href = $$.url('login');
        }
        if (global.window.location.pathname === $$.url('home')) {
            this.canLoadChildren = true;
        }
        this.getCountryCodeList();
        this.stores.MenuCustom.on('menu:load', () => {
            this.canLoadChildren = true;
        });
    }
}

export default Store;